<?php

namespace IDock\Insurance\ACIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ACIC\ACICEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllACICResponse
{
    public function printerInit(): Response
    {
        $vehicleModel= $this->get('VehicleModel',[]);
        if (!isset($vehicleModel[0])) {
            $modelList[] = $this->get('VehicleModel',[]);
        } else {
            $modelList = $this->get('VehicleModel',[]);
        }

        $vehicleModelPrinter = new VehicleModelPrinter();

        foreach ($modelList as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['Model'] ?? '';
            $vehiclePrinter->brandName = $datum['BrandName'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['DisplaceMentEx'] ?? '';
            $vehicleType = $datum['IpmORLoc'] ?? 0 ?: 0;

            $vehiclePrinter->vehicleImport = ACICEnums::$importFlag[$vehicleType];
            $vehiclePrinter->vehicleImportName=  IDockEnums::$importFlag[$vehiclePrinter->vehicleImport];

            $vehiclePrinter->isNewEnergy = $datum['IsNewFuelVhl'] ?? '';
            $vehiclePrinter->vehicleName = $datum['CarName'] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['ReplacementValue'] ?? '';
            $vehiclePrinter->vehiclePriceTax = $datum['ReplacementValue'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['CSeat'] ?? '';
            $vehiclePrinter->remark = '';

            $vehiclePrinter->familyName = $datum['FamilyName'] ?? '';
            $vehiclePrinter->power = $datum['Power'] ?? '';
            $vehiclePrinter->vehicleYear = $datum['VhlYear'] ?? '';
            $vehiclePrinter->vehicleTonnage = $datum['Tonnage'] ?? '';
            $vehiclePrinter->wholeWeight = $datum['Whole_Weight'] ?? '';
            $vehiclePrinter->energyTypeCode = ACICEnums::$energyType[$datum['FuelType'] ?? ''];
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode];
            $taxReduceCode = $datum['HfName'] ?? 'TR0';
            if ($taxReduceCode == '减半') {
                $vehiclePrinter->taxReduceCode  = 'TR2';
            }

            $vehiclePrinter->taxReduceName = IDockEnums::$taxReduceCode[$vehiclePrinter->taxReduceCode];

            //$vehiclePrinter->item = $datum;

            $vehicleModelPrinter->setModelList($vehiclePrinter);
        }

        $this->printer = $vehicleModelPrinter;

        return $this;
    }
}